﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class UserControl_ucProduct : System.Web.UI.UserControl
{
    int pId;
    public int Product_id;
    public string Model;
    public string Url;
    public int Category_id;
    
    public DateTime DateStart;
    public DateTime DateUpdate;
    public string Tag;
    public bool Status;
    public float Price_input;
    public float Price_output;
    public int Baohanh_id;
    public int View;
    public bool Top;
    public int AddressBaohanh_id;
    public int Quantity;
    public string Tinhnangnoibat;
    public string Trangthaiphathanh;
    public string Ngaycongbo;
    public string Ngayphathanh;
    public string Bangtan;
    public string Chieudai;
    public string Chieurong;
    public string Chieucao;
    public string Cannang;
    public string Kieumanhinh;
    public string Kichthuocmanhinh;
    public string Dophangiai;
    public string Camung;
    public string Tinhnangkhac;
    public string Tinnhan;
    public string Jackcam;
    public string Tainhacchuong;
    public string Loangoai;
    public string Danhbaluutru;
    public string Hotrosms;
    public string Hotroemail;
    public string Bonhotrong;
    public string Dungluongthenho;
    public string Loaithenho;
    public string Gprs;
    public string Edge;
    public string BaG;
    public string Web;
    public string Gps;
    public string Bluetooth;
    public string Wifi;
    public string Hongngoai;
    public string Usb;
    public string Mayanhchinh;
    public string Mayanhkhac;
    public string Mayanhphu ;
    public string Quayphim ;
    public string Nghenhac ;
    public string Xemphim ;
    public string Radio ;
    public string Tivi ;
    public string Ketnoitivi ;
    public string Ghiam ;
    public string Luutrucuocgoi ;
    public string Ungdungvanphong ;
    public string Ungdungkhac ;
    public string Trochoi ;
    public string Hotrosim;
    public string Hotrojava ;
    public string Kieudang ;
    public string Hedieuhanh ;
    public string Phienbanhedieuhanh ;
    public string Cpu ;
    public string Ram ;
    public string Ngonngu ;
    public string Qwerty ;
    public string Hotromang ;
    public string Loaipin ;
    public string Thoigiancho2g ;
    public string Thoigiancho3g ;
    public string Damthoai2g ;
    public string Damthoai3g ;
    public string Dungluongpin ;
    public string Image ;
    public string Description ;

    public string cateName;
    public int cateId;
    public string khohang;
    public string danhmucsanpham;
    public string color;
    public string address;
    public string publicDate;
    public string[] _tinhnangnoibat;

    ProductsController productControl=new ProductsController();
    CategoryController cateControl=new CategoryController();
    DanhmucsanphamController danhmucsanphamControl = new DanhmucsanphamController();
    ColorsController colorControl = new ColorsController();
    AddressController addressControl = new AddressController();
    BaohanhController baohanhControl=new BaohanhController();

    DataTable dtProduct;
    DataTable dtCategory;
    DataTable dtDanhmucsanpham;
    DataTable dtColor;
    DataTable dtAddress;
    DataTable dtBaohanh;
    DataTable dtOther;
    DataTable dtPhukienlienquan;

    public List<Products> listProduct = new List<Products>();

    protected void Page_Load(object sender, EventArgs e)
    {
        pId = Convert.ToInt16(Request["productId"]);
        productControl.UpdateView(pId);
        dtProduct=productControl.GetByID(pId);
        loadProperty();
        loadString();
    }
    public void loadString() {
        dtCategory = cateControl.getCategoryByID(Category_id);
        dtDanhmucsanpham = danhmucsanphamControl.GetByProductId(Product_id);
        foreach (DataRow item in dtDanhmucsanpham.Rows)
        {
            danhmucsanpham += item["name"]+",";
        }
        danhmucsanpham = string.IsNullOrEmpty(danhmucsanpham) ? "..." : danhmucsanpham;

        dtColor = colorControl.GetByProductId(Product_id);
        foreach (DataRow item in dtColor.Rows)
        {
            color += item["name"]+",";
        }
        color = string.IsNullOrEmpty(color) ? "..." : color;

        dtBaohanh = baohanhControl.GetByProductId(Product_id);
        dtlBaohanh.DataSource = dtBaohanh;
        dtlBaohanh.DataBind();

        dtAddress = addressControl.GetByProductID(Product_id);
        dtlAddress.DataSource = dtAddress;
        dtlAddress.DataBind();
        
        cateName = (dtCategory.Rows[0]["name"]).ToString();
        cateId = Convert.ToInt32(dtCategory.Rows[0]["category_id"]);
        khohang = (Status==true) ? "Còn hàng" : "Hết hàng";

        dtOther = productControl.GetOther();
        rptOther.DataSource = dtOther;
        rptOther.DataBind();

        publicDate = string.IsNullOrEmpty(DateUpdate.ToLongDateString()) ? DateStart.ToLongDateString() : DateUpdate.ToLongDateString();

        Trangthaiphathanh=string.IsNullOrEmpty(Trangthaiphathanh)?"...":Trangthaiphathanh;

        Ngaycongbo = string.IsNullOrEmpty(Ngaycongbo) ? "..." : Ngaycongbo;

        dtPhukienlienquan = productControl.GetPhukienLienquan(Product_id);
        dtlPhukientuongthich.DataSource = dtPhukienlienquan;
        dtlPhukientuongthich.DataBind();
    }
    public void loadProperty(){
        foreach (DataRow dr in dtProduct.Rows)
	    {
		    this.Product_id = Convert.ToInt32(dr[0].ToString());
            this.Model = dr[1].ToString();
            this.Url = dr[2].ToString();
            this.Category_id = Convert.ToInt32(dr[3].ToString());
            this.DateStart = DateTime.Parse(dr[4].ToString());
            if (dr[5].ToString() != null && dr[5].ToString()!="")
                this.DateUpdate = DateTime.Parse(dr[5].ToString());
            this.Tag = dr[6].ToString();
            this.Status = Boolean.Parse(dr[7].ToString());
            this.Price_input = Convert.ToSingle(dr[8].ToString());
            this.Price_output = Convert.ToSingle(dr[9].ToString());
            this.Baohanh_id = Convert.ToInt32(dr[10].ToString());
            this.View = Convert.ToInt32(dr[11].ToString());
            this.Top = Convert.ToBoolean(dr[12].ToString());
            this.AddressBaohanh_id = Convert.ToInt32(dr[13].ToString());
            this.Quantity = Convert.ToInt32(dr[14].ToString());
            this.Tinhnangnoibat = dr[15].ToString();
            this.Trangthaiphathanh = dr[16].ToString();
            this.Ngaycongbo = string.IsNullOrEmpty(dr[17].ToString()) ? "..." : dr[17].ToString();
            this.Ngayphathanh = string.IsNullOrEmpty(dr[18].ToString()) ? "..." : dr[18].ToString();
            this.Bangtan = string.IsNullOrEmpty(dr[19].ToString()) ? "..." : dr[19].ToString();
            this.Chieudai = string.IsNullOrEmpty(dr[20].ToString()) ? "..." : dr[20].ToString();
            this.Chieurong = string.IsNullOrEmpty(dr[21].ToString()) ? "..." : dr[21].ToString();
            this.Chieucao = string.IsNullOrEmpty(dr[22].ToString()) ? "..." : dr[22].ToString();
            this.Cannang = string.IsNullOrEmpty(dr[23].ToString()) ? "..." : dr[23].ToString();
            this.Kieumanhinh = string.IsNullOrEmpty(dr[24].ToString()) ? "..." : dr[24].ToString();
            this.Kichthuocmanhinh = string.IsNullOrEmpty(dr[25].ToString()) ? "..." : dr[25].ToString();
            this.Dophangiai = string.IsNullOrEmpty(dr[26].ToString()) ? "..." : dr[26].ToString();
            this.Camung = string.IsNullOrEmpty(dr[27].ToString()) ? "..." : dr[27].ToString();
            this.Tinhnangkhac = string.IsNullOrEmpty(dr[28].ToString()) ? "..." : dr[28].ToString();
            this.Tinnhan = string.IsNullOrEmpty(dr[29].ToString()) ? "..." : dr[29].ToString();
            this.Jackcam = string.IsNullOrEmpty(dr[30].ToString()) ? "..." : dr[30].ToString();
            this.Tainhacchuong = string.IsNullOrEmpty(dr[31].ToString()) ? "..." : dr[31].ToString();
            this.Loangoai = string.IsNullOrEmpty(dr[32].ToString()) ? "..." : dr[32].ToString();
            this.Danhbaluutru = string.IsNullOrEmpty(dr[33].ToString()) ? "..." : dr[33].ToString();
            this.Hotrosms = string.IsNullOrEmpty(dr[34].ToString()) ? "..." : dr[34].ToString();
            this.Hotroemail = string.IsNullOrEmpty(dr[35].ToString()) ? "..." : dr[35].ToString();
            this.Bonhotrong = string.IsNullOrEmpty(dr[36].ToString()) ? "..." : dr[36].ToString();
            this.Dungluongthenho = string.IsNullOrEmpty(dr[37].ToString()) ? "..." : dr[37].ToString();
            this.Loaithenho = string.IsNullOrEmpty(dr[38].ToString()) ? "..." : dr[38].ToString();
            this.Gprs = string.IsNullOrEmpty(dr[39].ToString()) ? "..." : dr[39].ToString();
            this.Edge = string.IsNullOrEmpty(dr[40].ToString()) ? "..." : dr[40].ToString();
            this.BaG = string.IsNullOrEmpty(dr[41].ToString()) ? "..." : dr[41].ToString();
            this.Web = string.IsNullOrEmpty(dr[42].ToString()) ? "..." : dr[42].ToString();
            this.Gps = string.IsNullOrEmpty(dr[43].ToString()) ? "..." : dr[43].ToString();
            this.Bluetooth = string.IsNullOrEmpty(dr[44].ToString()) ? "..." : dr[44].ToString();
            this.Wifi = string.IsNullOrEmpty(dr[45].ToString()) ? "..." : dr[45].ToString();
            this.Hongngoai = string.IsNullOrEmpty(dr[46].ToString()) ? "..." : dr[46].ToString();
            this.Usb = string.IsNullOrEmpty(dr[47].ToString()) ? "..." : dr[47].ToString();
            this.Mayanhchinh = string.IsNullOrEmpty(dr[48].ToString()) ? "..." : dr[48].ToString();
            this.Mayanhkhac = string.IsNullOrEmpty(dr[49].ToString()) ? "..." : dr[49].ToString();
            this.Mayanhphu = string.IsNullOrEmpty(dr[50].ToString()) ? "..." : dr[50].ToString();
            this.Quayphim = string.IsNullOrEmpty(dr[51].ToString()) ? "..." : dr[51].ToString();
            this.Nghenhac = string.IsNullOrEmpty(dr[52].ToString()) ? "..." : dr[52].ToString();
            this.Xemphim = string.IsNullOrEmpty(dr[53].ToString()) ? "..." : dr[53].ToString();
            this.Radio = string.IsNullOrEmpty(dr[54].ToString()) ? "..." : dr[54].ToString();
            this.Tivi = string.IsNullOrEmpty(dr[55].ToString()) ? "..." : dr[55].ToString();
            this.Ketnoitivi = string.IsNullOrEmpty(dr[56].ToString()) ? "..." : dr[56].ToString();
            this.Ghiam = string.IsNullOrEmpty(dr[57].ToString()) ? "..." : dr[57].ToString();
            this.Luutrucuocgoi = string.IsNullOrEmpty(dr[58].ToString()) ? "..." : dr[58].ToString();
            this.Ungdungvanphong = string.IsNullOrEmpty(dr[59].ToString()) ? "..." : dr[59].ToString();
            this.Ungdungkhac = string.IsNullOrEmpty(dr[60].ToString()) ? "..." : dr[60].ToString();
            this.Trochoi = string.IsNullOrEmpty(dr[61].ToString()) ? "..." : dr[61].ToString();
            this.Hotrosim = string.IsNullOrEmpty(dr[62].ToString()) ? "..." : dr[62].ToString();
            this.Hotrojava = string.IsNullOrEmpty(dr[63].ToString()) ? "..." : dr[63].ToString();
            this.Kieudang = string.IsNullOrEmpty(dr[64].ToString()) ? "..." : dr[64].ToString();
            this.Hedieuhanh = string.IsNullOrEmpty(dr[65].ToString()) ? "..." : dr[65].ToString();
            this.Phienbanhedieuhanh = string.IsNullOrEmpty(dr[66].ToString()) ? "..." : dr[66].ToString();
            this.Cpu = string.IsNullOrEmpty(dr[67].ToString()) ? "..." : dr[67].ToString();
            this.Ram = string.IsNullOrEmpty(dr[68].ToString()) ? "..." : dr[68].ToString();
            this.Ngonngu = string.IsNullOrEmpty(dr[69].ToString()) ? "..." : dr[69].ToString();
            this.Qwerty = string.IsNullOrEmpty(dr[70].ToString()) ? "..." : dr[70].ToString();
            this.Hotromang = string.IsNullOrEmpty(dr[71].ToString()) ? "..." : dr[71].ToString();
            this.Loaipin = string.IsNullOrEmpty(dr[72].ToString()) ? "..." : dr[72].ToString();
            this.Thoigiancho2g = string.IsNullOrEmpty(dr[73].ToString()) ? "..." : dr[73].ToString();
            this.Thoigiancho3g = string.IsNullOrEmpty(dr[74].ToString()) ? "..." : dr[74].ToString();
            this.Damthoai2g = string.IsNullOrEmpty(dr[75].ToString()) ? "..." : dr[75].ToString();
            this.Damthoai3g = string.IsNullOrEmpty(dr[76].ToString()) ? "..." : dr[76].ToString();
            this.Dungluongpin = string.IsNullOrEmpty(dr[77].ToString()) ? "..." : dr[77].ToString();
            this.Image = dr[78].ToString();
            this.Description = string.IsNullOrEmpty(dr[79].ToString()) ? "..." : dr[79].ToString();
	    }
    }
}